//package com.bussiness.controller;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.bussiness.model.Article;
//import com.common.response.ResponseBean;
//import com.common.response.impl.BaseResponseImpl;
//import com.common.util.SnowflakeIdWorker;
//import com.elastic.util.Esutil;
//import com.eshbase.model.EsHbaseModel;
//import com.eshbase.util.EsHbaseUtil;
//import com.hbase.util.HbaseAdmin;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//import org.elasticsearch.common.unit.TimeValue;
//import org.elasticsearch.index.query.BoolQueryBuilder;
//import org.elasticsearch.index.query.FuzzyQueryBuilder;
//import org.elasticsearch.index.query.QueryBuilders;
//import org.elasticsearch.search.builder.SearchSourceBuilder;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.TimeUnit;
//
//
///**
// * @description: es-hbase
// * @author: zyj
// * @create: 2019-12-16 10:38
// **/
//@RestController
//@Api(tags={"es-hbase整合测试"})
//@RequestMapping("/esHbase")
//public class EsHbaseController extends BaseResponseImpl {
//
//    @Autowired
//    private EsHbaseUtil esHbaseUtil;
//
//    @Autowired
//    private Esutil esutil;
//
//    @Autowired
//    private HbaseAdmin hbaseAdmin;
//
//    SnowflakeIdWorker snowflakeIdWorker = SnowflakeIdWorker.getInstance();
//
//
//    @ApiOperation(value="添加表名-索引")
//    @RequestMapping(value = "/createIndex", method = RequestMethod.PUT)
//    public ResponseBean createIndex(@RequestBody EsHbaseModel esHbaseModel) {
//        boolean b = esHbaseUtil.createTable(esHbaseModel);
//        if(b){
//            return success();
//        }
//        return error();
//    }
//
//
//    @ApiOperation(value="添加数据")
//    @RequestMapping(value = "/insertContent", method = RequestMethod.PUT)
//    public ResponseBean insertContent(@RequestBody Article article, @ApiParam(value = "表名") @RequestParam String indexName
//            , @ApiParam(value = "列族") @RequestParam String columnFamily){
//        String row = String.valueOf(snowflakeIdWorker.nextId());
//        article.setRowKey(row);
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("context", article.getContext());
//        jsonObject.put("rowKey", row);
//        boolean b = esHbaseUtil.insertContentOne((JSONObject) JSON.toJSON(article), jsonObject, row, columnFamily, indexName);
//        if(b){
//            return success();
//        }
//        return error();
//    }
//
//
//    @ApiOperation(value="查询数据")
//    @RequestMapping(value = "/listContent", method = RequestMethod.GET)
//    public ResponseBean listContent(@RequestParam String indexName,@RequestParam String key,@RequestParam String value
//            ,@RequestParam int page,@RequestParam int size){
//        try {
//            FuzzyQueryBuilder fuzzyQueryBuilder = QueryBuilders.fuzzyQuery(key, value);
//            /**查询条件拼接  should:查询条件or的关系*/
//            BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
//            boolQueryBuilder.filter(fuzzyQueryBuilder);
//
//            /**排序*/
//            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
//
//            /**查询条件*/
//            sourceBuilder.query(boolQueryBuilder);
//            /** 第几页*/
//            int start = (page-1)*size;
//            sourceBuilder.from(start);
//            /** 每页多少条数据*/
//            sourceBuilder.size(size);
//            /**超时时间*/
//            sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
//            JSONArray jsonArray = esutil.queryIndex(sourceBuilder, indexName);
//
//            List<String> list = new ArrayList<>();
//            for(int i=0;i<jsonArray.size();i++){
//                JSONObject jsonObject = jsonArray.getJSONObject(i);
//                list.add(jsonObject.getString("rowKey"));
//            }
//            List<Map<String,Object>> result = hbaseAdmin.selectRowDataList(indexName, list);
//
//            return successData(result);
//        } catch (Exception e){
//            e.printStackTrace();
//        }
//
//        return error();
//    }
//
//
//}
